package com.ps.property;

import java.io.Serializable;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 *  响应VO
 * @author Administrator
 *
 */
@SuppressWarnings("serial")
@ApiModel("响应结果")
@Data
public class ResponseVO<T> implements Serializable{
	
	@ApiModelProperty(value = "操作是否成功，true是,false否")
	boolean success;
	@ApiModelProperty(value = "状态码")
	int code;
	@ApiModelProperty(value = "状态码信息")
	String msg;
	@ApiModelProperty(value = "响应数据对象")
	T data;
	
	public static <T> ResponseVO<T> success(T t) {
		ResponseVO<T> vo=new ResponseVO<T>();
		vo.setSuccess(true);
		vo.setCode(ResultCode.CODE_1.getCode());
		vo.setMsg(ResultCode.CODE_1.getMsg());
		vo.setData(t);
		return vo;
	}
	
	public static <T> ResponseVO<T> fail(String msg) {
		ResponseVO<T> vo=new ResponseVO<T>();
		vo.setSuccess(false);
		vo.setCode(ResultCode.CODE_1.getCode());
		vo.setMsg(msg);
		vo.setData(null);
		return vo;
	}
	
	public static <T> ResponseVO<T> fail(ResultCode code) {
		ResponseVO<T> vo=new ResponseVO<T>();
		vo.setSuccess(false);
		vo.setCode(code.getCode());
		vo.setMsg(code.getMsg());
		vo.setData(null);
		return vo;
	}
	
	public static <T> ResponseVO<T> fail(int code,String msg) {
		ResponseVO<T> vo=new ResponseVO<T>();
		vo.setSuccess(false);
		vo.setCode(code);
		vo.setMsg(msg);
		vo.setData(null);
		return vo;
	}
}
